//
//  LFBNavBar.m
//  LFBLoveFreshBee
//
//  Created by 丁鼎 on 16/8/19.
//  Copyright © 2016年 丁鼎. All rights reserved.
//

#import "LFBNavBar.h"
#import "LFBShopppingTrolleyBtn.h"

@interface LFBNavBar ()
@property (nonatomic,weak) LFBShopppingTrolleyBtn *scanBtn;

@property (nonatomic,weak) LFBShopppingTrolleyBtn *searchBtn;

@property (nonatomic,weak)UIButton *address;

@property (nonatomic,weak) UILabel *send;

@end

@implementation LFBNavBar

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    
    self.backgroundColor = KThemeColor;
    
    LFBShopppingTrolleyBtn *btn1 = [[LFBShopppingTrolleyBtn alloc]init];
    self.scanBtn = btn1;
    
    [btn1 setImage:[UIImage imageNamed:@"icon_black_scancode"] forState:UIControlStateNormal];
    
    [btn1 setTitle:@"扫一扫" forState:UIControlStateNormal];
    
    btn1.titleLabel.font = [UIFont systemFontOfSize:10];
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(scanBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:btn1];
    
    
    LFBShopppingTrolleyBtn *btn2 = [[LFBShopppingTrolleyBtn alloc]init];
    
    self.searchBtn = btn2;
    
    [btn2 setImage:[UIImage imageNamed:@"icon_search"] forState:UIControlStateNormal];
    [btn2 setTitle:@"搜索" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    btn2.titleLabel.font = [UIFont systemFontOfSize:10];
    [btn2 sizeToFit];
    [self addSubview:btn2];
    [btn2 addTarget:self action:@selector(searchBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *send = [[UILabel alloc]init];
    send.text = @"配送至:";
    self.send = send;
    send.font = [UIFont systemFontOfSize:14];
    [send sizeToFit];
    [self addSubview:send];
    
    UIButton *address = [UIButton new];
    self.address = address;
    [address setTitle:@"你在哪里呀?" forState:UIControlStateNormal];
    [self.address setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.address addTarget:self action:@selector(addressTitle:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:address];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.scanBtn.frame = CGRectMake(0, 20, 60, 50);
    
    self.searchBtn.frame = CGRectMake(325, 20, 50, 50);
    
    self.send.centerX = self.centerX - 50;
    
    self.send.y = 30;
    
    self.address.x = self.send.x+self.send.width;
    self.address.size = CGSizeMake(100, 40);
    self.address.y = 20;
}


-(void)searchBtn:(UIButton *)sender{
    if ([self.navdelegate respondsToSelector:@selector(clickSearchBtn:)])
    {
        [self.navdelegate clickSearchBtn:self];
    }
}

-(void)scanBtn:(UIButton *)sender
{
    if([self.navdelegate respondsToSelector:@selector(clickScanBtn:)])
    {
        [self.navdelegate clickScanBtn:self];
    }
    
}

-(void)addressTitle:(UIButton *)button{
    if([self.navdelegate  respondsToSelector:@selector(clickSearchBtn:)])
    {
        [self.navdelegate clickAddressTitle:self];
    }
}
@end

